package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.Users;
import com.ruoyi.system.service.IUsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author Vincent
 * @ClassName RoleAssociatedUserController
 * @Date 2025-05-19-14:16
 * @PackageName com.ruoyi.web.controller.system
 * @Description
 */
@RestController
@RequestMapping("/system/role-associated-users")
public class RoleAssociatedUserController extends BaseController {

    @Autowired
    private IUsersService usersService;

    @GetMapping
    public List<Users> getAssociatedUsers(Users users) {
        users.setRid(3L);
        return usersService.selectUserByRoleIdAndConditions(users);
    }

    // 取消关联
    @PostMapping("/cancel-association")
    public AjaxResult cancelUserAssociation(@RequestBody Long[] userIds) {
        if (userIds == null || userIds.length == 0) {
            return error("请选择要取消关联的用户");
        }
        usersService.updateUsersRidToNullByIds(userIds);
        return success();
    }
}

